package demo04;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class URLdownload {

    public static void main(String[] args) throws Exception {
        //下载地址
        URL url = new URL("https://m801.music.126.net/20210527101819/4af87d7c28a45bc5ec16697f5a8fd31f/jdyyaac/565b/065f/0358/a1cd0e25a815dffcc0c1422398efde9e.m4a");
        //连接到这个资源http
        HttpURLConnection urlConnection =(HttpURLConnection) url.openConnection();

        InputStream inputStream = urlConnection.getInputStream();

        FileOutputStream fos = new FileOutputStream("9e.m4a");

        byte[] buffer = new byte[1024];
        int len;
        while ((len=inputStream.read(buffer))!=-1){
            fos.write(buffer,0,len);


        }
        fos.close();
        inputStream.close();
        urlConnection.disconnect();


    }
}
